package com.ruoyi.project.storage.controller;

import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.common.enums.TerminalEnum;
import com.ruoyi.project.common.util.CheckUtil;
import com.ruoyi.project.storage.domain.User;
import com.ruoyi.project.storage.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 注册Controller
 *
 * @author mengyuanqing
 * @date 2020/5/3
 */
@RestController
@RequestMapping("/app/regist")
@Api(tags = {"【手机端】5.2.1 注册"},description = "填写注册信息")
public class AppRegistController extends BaseController {
    // 通过注释注入用户Service
    @Autowired
    private IUserService userService;

    /**
     * 注册
     *
     * @param user 用户对象
     * @return 结果
     */
    @Log(title = "5.2.1 注册", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation(value = "5.2.1 注册", notes = "注册客户")
    public AjaxResult regist(@RequestBody User user) {
        // 校验用户唯一
        AjaxResult ajaxResult = CheckUtil.checkUserUnique(user,1);
        // 返回通用返回实体(非分页)
        return ajaxResult==null ? toAjax(userService.insertUser(TerminalEnum.REGIST,user)):ajaxResult;
    }
}
